<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script>
      var a = [23, 56, 32, 7, 10, 9, 77, 2];
      var j, temp;

      for (i = 1; i < a.length; i++) {
        j = i - 1;
        temp = a[i];
        while (j >= 0 && a[j] > temp) {
          a[j + 1] = a[j];
          j--;
        }
        a[j + 1] = temp;
      }
      console.log(a);
    </script>
  </body>
</html>
